package org.tib.concurrent;

import java.math.BigInteger;

/**
 * Factorial of n (denoted as n!) is usually = n(n-1) * (n-2)..* 1
 * Where 0! = 1
 */
public class Factorial {

    /**
     * Finding the factorial of a given number.
     * @param n The number to derive the factorial for.
     * @return The factorial of the given number
     */
    public BigInteger computeFactorial(Integer n) {
        BigInteger val = BigInteger.valueOf(n);
        if(n == 0) {
            return BigInteger.valueOf(1);
        }
        else {
            return val.multiply(computeFactorial(n -1));
        }
    }

    public static void main(String[] args) {
        Factorial fact = new Factorial();
        int n = 5; // factorial should be 120 -> (5*4*3*2*1)
        System.out.println("The factorial of "+ n + " is : "+ fact.computeFactorial(n));
    }
}
